Use custom Terraform provider release to generate schema.json - #1318
Conversation
76feab1 to
b7dfb86
Compare
ulucinar
left a comment
There was a problem hiding this comment.
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.
| @$(OK) installing terraform $(HOSTOS)-$(HOSTARCH) | ||
|
|
||
| $(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM) | ||
| $(TERRAFORM_PROVIDER): |
There was a problem hiding this comment.
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.
|
|
||
| $(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM) | ||
| $(TERRAFORM_PROVIDER): | ||
| @$(INFO) installing terraform provider $(SAFEHOST_PLATFORM) |
There was a problem hiding this comment.
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.
Please see the comment above about incorporating the upjet release iteration number.
| $(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.
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.
| @$(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.
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
|
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
.terraformrcconfiguration 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.0is 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-awson 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-awson an Intel/AMD Linux).I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
config/schema.json.make config/schema.json.config/schema.jsonis 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_userschema exists in the output,config/schema.json.