Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Support selecting a workspace in tfInit
Browse files Browse the repository at this point in the history
  • Loading branch information
ayltai committed Sep 18, 2020
1 parent bb93591 commit ac7a194
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Supports for executing [Terraform](https://www.terraform.io) [command-line tools
Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):
```groovy
plugins {
id 'com.github.ayltai.terraform-plugin' version '0.2.5'
id 'com.github.ayltai.terraform-plugin' version '0.2.13'
}
```

Expand All @@ -43,7 +43,7 @@ buildscript {
}
dependencies {
classpath 'gradle.plugin.com.github.ayltai:terraform-plugin:0.2.5'
classpath 'gradle.plugin.com.github.ayltai:terraform-plugin:0.2.13'
}
}
Expand All @@ -54,7 +54,7 @@ apply plugin: 'com.github.ayltai.terraform-plugin'
Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):
```groovy
plugins {
id('com.github.ayltai.terraform-plugin') version '0.2.5'
id('com.github.ayltai.terraform-plugin') version '0.2.13'
}
```

Expand All @@ -68,7 +68,7 @@ buildscript {
}
dependencies {
classpath('gradle.plugin.com.github.ayltai:terraform-plugin:0.2.5')
classpath('gradle.plugin.com.github.ayltai:terraform-plugin:0.2.13')
}
}
```
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/github/ayltai/gradle/plugin/InitTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
Expand All @@ -18,12 +19,14 @@ public class InitTask extends StatefulTask {

protected final Property<Boolean> useBackend;
protected final Property<Boolean> upgrade;
protected final Property<String> workspace;

//endregion

public InitTask() {
this.useBackend = this.getProject().getObjects().property(Boolean.class);
this.upgrade = this.getProject().getObjects().property(Boolean.class);
this.workspace = this.getProject().getObjects().property(String.class);

this.setGroup(Constants.GROUP_BUILD_SETUP);
this.setDescription("Initialize Terraform source scripts.");
Expand All @@ -45,6 +48,12 @@ public Property<Boolean> getUpgrade() {
return this.upgrade;
}

@Nullable
@Internal
protected String getWorkspace() {
return this.workspace.getOrNull();
}

@Nonnull
@OutputDirectory
public File getPluginsDirectory() {
Expand All @@ -68,4 +77,11 @@ protected List<String> getCommandLineArgs() {

return args;
}

@Override
protected void exec() {
if (this.getWorkspace() != null) this.environment("TF_WORKSPACE", this.getWorkspace());

super.exec();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ protected void exec() {
throw new ResourceException("Failed to save credentials to " + this.getCredentials().getAbsolutePath(), e);
}

this.environment("TF_CLI_CONFIG_FILE", this.configFile.isPresent() ? this.configFile.getAsFile().get().getAbsolutePath() : this.getCredentials().getAbsolutePath());
this.environment("TF_CLI_CONFIG_FILE", this.configFile.isPresent() ? this.configFile.getAsFile().get().getAbsolutePath() : this.getCredentials().getAbsolutePath())
.environment("TF_IN_AUTOMATION", true);

super.exec();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private static void registerInitTask(@Nonnull final Project project, @Nonnull fi

task.useBackend.set(options.useBackend);
task.upgrade.set(options.upgrade);
task.workspace.set(extension.getWorkspace());

TerraformPlugin.configureStatefulTask(task, extension, options);
});
Expand Down

0 comments on commit ac7a194

Please sign in to comment.