-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use custom Terraform provider release to generate schema.json #1318
Use custom Terraform provider release to generate schema.json #1318
Conversation
76feab1
to
b7dfb86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mergenci for changing the provider's build pipeline so that we can use the newly added native resource schemas during the code generation phase. We will hopefully remove the need for this when we switch from using the JSON provider schema to the Go schema.
@@ -169,12 +172,21 @@ $(TERRAFORM): | |||
@rm -fr $(TOOLS_HOST_DIR)/tmp-terraform | |||
@$(OK) installing terraform $(HOSTOS)-$(HOSTARCH) | |||
|
|||
$(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM) | |||
$(TERRAFORM_PROVIDER): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to incorporate the upjet iteration from the consumed release version as part of this target's name. Otherwise, when for instance, we release v5.31.0-upjet.2
, this target may decide not to download the correct version and use the older, already cached v5.31.0-upjet.1
version.
Makefile
Outdated
@@ -169,12 +172,21 @@ $(TERRAFORM): | |||
@rm -fr $(TOOLS_HOST_DIR)/tmp-terraform | |||
@$(OK) installing terraform $(HOSTOS)-$(HOSTARCH) | |||
|
|||
$(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM) | |||
$(TERRAFORM_PROVIDER): | |||
@$(INFO) installing terraform provider $(SAFEHOST_PLATFORM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
@$(INFO) installing terraform provider $(SAFEHOST_PLATFORM) | |
@$(INFO) installing terraform AWS provider for the platform $(SAFEHOST_PLATFORM) |
$(TERRAFORM_PROVIDER): | ||
@$(INFO) installing terraform provider $(SAFEHOST_PLATFORM) | ||
@mkdir -p $$(dirname $(TERRAFORM_PROVIDER)) | ||
@curl -fsSL https://github.com/upbound/terraform-provider-aws/releases/download/$(TERRAFORM_PROVIDER_RELEASE)/terraform-provider-aws_$(TERRAFORM_PROVIDER_RELEASE)_$(SAFEHOST_PLATFORM).zip -o $(TERRAFORM_PROVIDER).zip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the comment above about incorporating the upjet release iteration number.
@rm -fr $(TERRAFORM_PROVIDER).zip | ||
@$(OK) installing terraform provider $(SAFEHOST_PLATFORM) | ||
|
||
$(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM) $(TERRAFORM_PROVIDER) | ||
@$(INFO) generating provider schema for $(TERRAFORM_PROVIDER_SOURCE) $(TERRAFORM_PROVIDER_VERSION) | ||
@mkdir -p $(TERRAFORM_WORKDIR) | ||
@echo '{"terraform":[{"required_providers":[{"provider":{"source":"'"$(TERRAFORM_PROVIDER_SOURCE)"'","version":"'"$(TERRAFORM_PROVIDER_VERSION)"'"}}],"required_version":"'"$(TERRAFORM_VERSION)"'"}]}' > $(TERRAFORM_WORKDIR)/main.tf.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Currently when you examine the provider block, it looks like we are using a vanilla Terraform AWS provider (because the URI is till hashicorp/aws:v5.31.0
) however, we are using a custom built binary. We may, in a future PR, consider making this more explicit by changing the Terraform provider URI.
Makefile
Outdated
@$(INFO) installing terraform provider $(SAFEHOST_PLATFORM) | ||
@mkdir -p $$(dirname $(TERRAFORM_PROVIDER)) | ||
@curl -fsSL https://github.com/upbound/terraform-provider-aws/releases/download/$(TERRAFORM_PROVIDER_RELEASE)/terraform-provider-aws_$(TERRAFORM_PROVIDER_RELEASE)_$(SAFEHOST_PLATFORM).zip -o $(TERRAFORM_PROVIDER).zip | ||
@unzip $(TERRAFORM_PROVIDER).zip -d $$(dirname $(TERRAFORM_PROVIDER)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
@unzip $(TERRAFORM_PROVIDER).zip -d $$(dirname $(TERRAFORM_PROVIDER)) | |
@unzip $(TERRAFORM_PROVIDER).zip -d $(dir $(TERRAFORM_PROVIDER)) |
Signed-off-by: Cem Mergenci <cmergenci@gmail.com>
b7dfb86
to
2932f78
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mergenci, lgtm.
Thank you for your valuable reviews @ulucinar 🙏 |
Description of your changes
Code generation depends on JSON schema of terraform-provider-aws (
config/schema.json
). Converting a Terraform provider's schema to JSON is performed by Terraform CLI, which requires a provider binary. Therefore, when we introduce a new resource, such as MQ User, to our fork of terraform-provider-aws, we also release the provider as binary. This PR introduces necessary changes to download custom provider release and let Terraform CLI use it instead of the official provider.The following is an example
.terraformrc
configuration generated bymake
:When using the above configuration, Terraform CLI locates the provider binary at
registry.terraform.io/hashicorp/aws/5.31.0/darwin_arm64/terraform-provider-aws
, where5.31.0
is the example provider version, inside the filesystem mirror directory.Custom provider release is installed at
.cache/tools/darwin_arm64/registry.terraform.io/hashicorp/aws/5.31.0/darwin_arm64/terraform-provider-aws
on an Apple Silicon Mac. On other platforms, installation location is the equivalent path, for instance.cache/tools/linux_amd64/registry.terraform.io/hashicorp/aws/5.31.0/linux_amd64/terraform-provider-aws
on an Intel/AMD Linux).I have:
make reviewable
to ensure this PR is ready for review.backport release-x.y
labels to auto-backport this PR if necessary.How has this code been tested
config/schema.json
.make config/schema.json
.config/schema.json
is created.Above steps will not result in any difference in
config/schema.json
. During development, I used a development build of the provider that has a new resource,aws_mq_user
, added. In that case, I observed thataws_mq_user
schema exists in the output,config/schema.json
.