Skip to content

Commit

Permalink
Merge pull request #128 from ytsarev/make-run
Browse files Browse the repository at this point in the history
Fix `make run` for local development
  • Loading branch information
ytsarev committed Nov 7, 2022
2 parents c005998 + 7b9231f commit bc9577e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ cover.out

# ignore asdf local versions
/.tool-versions

# local tf dir
/tf
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ build.init: $(UP)
run: go.build
@$(INFO) Running Crossplane locally out-of-cluster . . .
@# To see other arguments that can be provided, run the command with --help instead
$(GO_OUT_DIR)/$(PROJECT_NAME) --debug
@# KUBE_CONFIG_PATH explained at https://developer.hashicorp.com/terraform/language/settings/backends/kubernetes
@# XP_TF_DIR is to override default tf work dir which is usually /tf and unreadable locally
KUBE_CONFIG_PATH=~/.kube/config XP_TF_DIR=./tf $(GO_OUT_DIR)/provider --debug

dev: $(KIND) $(KUBECTL)
@$(INFO) Creating kind cluster
Expand Down
2 changes: 1 addition & 1 deletion cluster/images/provider-terraform/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN cd /tmp \
&& unzip /tmp/terraform_${TERRAFORM_VERSION}_${TARGETOS}_${TARGETARCH}.zip -d /usr/local/bin \
&& chmod +x /usr/local/bin/terraform \
&& rm /tmp/terraform_${TERRAFORM_VERSION}_${TARGETOS}_${TARGETARCH}.zip

# As of Crossplane v1.3.0 provider controllers run as UID 2000.
# https://github.com/crossplane/crossplane/blob/v1.3.0/internal/controller/pkg/revision/deployment.go#L32
RUN mkdir /tf
Expand Down
15 changes: 13 additions & 2 deletions internal/controller/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ const (
const (
// TODO(negz): Make the Terraform binary path and work dir configurable.
tfPath = "terraform"
tfDir = "/tf"
tfMain = "main.tf"
tfConfig = "crossplane-provider-config.tf"
)

func envVarFallback(envvar string, fallback string) string {
if value, ok := os.LookupEnv(envvar); ok {
return value
}
return fallback
}

var tfDir = envVarFallback("XP_TF_DIR", "/tf")

type tfclient interface {
Init(ctx context.Context, o ...terraform.InitOption) error
Workspace(ctx context.Context, name string) error
Expand Down Expand Up @@ -254,7 +262,10 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E
*pc.Spec.PluginCache = true
}
if *pc.Spec.PluginCache {
pluginCacheDir := filepath.Join(tfDir, "plugin-cache")
pluginCacheDir, err := filepath.Abs(filepath.Join(tfDir, "plugin-cache"))
if err != nil {
return nil, errors.Wrap(err, errMkPluginCacheDir)
}
if err := c.fs.MkdirAll(pluginCacheDir, 0700); err != nil {
return nil, errors.Wrap(err, errMkPluginCacheDir)
}
Expand Down

0 comments on commit bc9577e

Please sign in to comment.