Skip to content

Commit

Permalink
Merge pull request #103 from jfrog/GH-102-mismatch-provider-type-in-o…
Browse files Browse the repository at this point in the history
…idc-config

Fix mismatch provider type in OIDC config
  • Loading branch information
alexhung authored Jul 3, 2024
2 parents 2b68662 + 534a492 commit eee7ea9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
57 changes: 17 additions & 40 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
matrix:
cli: [terraform, tofu]
outputs:
tf_version: ${{ steps.install_terraform_cli.outputs.version }}
tofu_version: ${{ steps.install_opentofu_cli.outputs.version }}
tf_version: ${{ steps.get_terraform_cli_version.outputs.version }}
tofu_version: ${{ steps.get_opentofu_cli_version.outputs.version }}
artifactory_version: ${{ steps.run_artifactory_container.outputs.version }}
steps:
- name: Checkout
Expand All @@ -33,54 +33,36 @@ jobs:
with:
go-version: 1.21
- name: Install Helm
run: |
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod +x get_helm.sh
./get_helm.sh
rm get_helm.sh
uses: azure/[email protected]
- name: Install Terraform CLI
id: install_terraform_cli
uses: hashicorp/setup-terraform@v3
if: ${{ matrix.cli == 'terraform' }}
- name: Get Terraform CLI version
id: get_terraform_cli_version
if: ${{ matrix.cli == 'terraform' }}
run: |
wget -q -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt-get update
sudo apt-get install -y terraform
TF_VERSION=$(terraform -v -json | jq -r .terraform_version)
echo $TF_VERSION
echo "version=$TF_VERSION" >> "$GITHUB_OUTPUT"
- name: Install OpenTofu CLI
id: install_opentofu_cli
uses: opentofu/setup-opentofu@v1
if: ${{ matrix.cli == 'tofu' }}
with:
tofu_wrapper: false
- name: Get OpenTofu CLI version
id: get_opentofu_cli_version
if: ${{ matrix.cli == 'tofu' }}
run: |
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
echo "Set up the OpenTofu repository"
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://get.opentofu.org/opentofu.gpg | sudo tee /etc/apt/keyrings/opentofu.gpg >/dev/null
curl -fsSL https://packages.opentofu.org/opentofu/tofu/gpgkey | sudo gpg --no-tty --batch --dearmor -o /etc/apt/keyrings/opentofu-repo.gpg >/dev/null
sudo chmod a+r /etc/apt/keyrings/opentofu.gpg /etc/apt/keyrings/opentofu-repo.gpg
echo "Create the OpenTofu source list"
echo \
"deb [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main
deb-src [signed-by=/etc/apt/keyrings/opentofu.gpg,/etc/apt/keyrings/opentofu-repo.gpg] https://packages.opentofu.org/opentofu/tofu/any/ any main" | \
sudo tee /etc/apt/sources.list.d/opentofu.list > /dev/null
sudo chmod a+r /etc/apt/sources.list.d/opentofu.list
echo "Installing OpenTofu"
sudo apt-get update
sudo apt-get install -y tofu
echo "TF_ACC_TERRAFORM_PATH=$(which tofu)" >> "$GITHUB_ENV"
echo "TF_ACC_PROVIDER_NAMESPACE=hashicorp" >> "$GITHUB_ENV"
echo "TF_ACC_PROVIDER_HOST=registry.opentofu.org" >> "$GITHUB_ENV"
TOFU_VERSION=$(tofu -v -json | jq -r .terraform_version)
echo $TOFU_VERSION
echo "version=$TOFU_VERSION" >> "$GITHUB_OUTPUT"
- name: Install GoReleaser
run: |
echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt-get update
sudo apt-get install -y goreleaser
uses: goreleaser/goreleaser-action@v6
with:
install-only: true
- name: Create Artifactory data directories and copy data
env:
ARTIFACTORY_LICENSE: ${{ secrets.ARTIFACTORY_LICENSE }}
Expand Down Expand Up @@ -139,17 +121,12 @@ jobs:
cat sample.tf | sed -e "s/version =.*/version = \"${PROVIDER_VERSION}\"/g" > sample.tf.tmp
cp sample.tf.tmp sample.tf && rm sample.tf.tmp
TERRAFORM_CLI=${{ matrix.cli }} make install
# - name: Dump Artifactory logs
# uses: jwalton/gh-docker-logs@v2
# if: failure()
# with:
# tail: '10000'
- name: Clean up Docker container
if: always()
run: docker stop artifactory
- name: Send workflow status to Slack
uses: slackapi/[email protected]
if: always()
if: always() && ${{ steps.run_artifactory_container.outcome == 'success' }}
with:
payload: |
{
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.8.1 (July 3, 2024). Tested on Artifactory 7.84.16 with Terraform 1.9.1 and OpenTofu 1.7.2

BUG FIXES:

* resource/platform_oidc_configuration: Fix `provider_type` attribute value stored incorrectly when resource is imported. Issue: [#102](https://github.com/jfrog/terraform-provider-platform/issues/102) PR: [#103](https://github.com/jfrog/terraform-provider-platform/pull/103)

## 1.8.0 (June 20, 2024). Tested on Artifactory 7.84.15 with Terraform 1.8.5 and OpenTofu 1.7.2

NOTES:
Expand Down
20 changes: 17 additions & 3 deletions pkg/platform/resource_oidc_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,15 @@ func (r *odicConfigurationResource) Create(ctx context.Context, req resource.Cre
return
}

providerType := plan.ProviderType.ValueString()
if providerType == "generic" {
providerType = "Generic OpenID Connect"
}

odicConfig := odicConfigurationAPIModel{
Name: plan.Name.ValueString(),
IssuerURL: plan.IssuerURL.ValueString(),
ProviderType: plan.ProviderType.ValueString(),
ProviderType: providerType,
Audience: plan.Audience.ValueString(),
Description: plan.Description.ValueString(),
}
Expand Down Expand Up @@ -208,7 +213,11 @@ func (r *odicConfigurationResource) Read(ctx context.Context, req resource.ReadR
state.Audience = types.StringValue(odicConfig.Audience)
}

state.ProviderType = types.StringValue(odicConfig.ProviderType)
if odicConfig.ProviderType == "Generic OpenID Connect" {
state.ProviderType = types.StringValue("generic")
} else {
state.ProviderType = types.StringValue(odicConfig.ProviderType)
}

resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}
Expand All @@ -221,10 +230,15 @@ func (r *odicConfigurationResource) Update(ctx context.Context, req resource.Upd
return
}

providerType := plan.ProviderType.ValueString()
if providerType == "generic" {
providerType = "Generic OpenID Connect"
}

odicConfig := odicConfigurationAPIModel{
Name: plan.Name.ValueString(),
IssuerURL: plan.IssuerURL.ValueString(),
ProviderType: plan.ProviderType.ValueString(),
ProviderType: providerType,
Audience: plan.Audience.ValueString(),
Description: plan.Description.ValueString(),
}
Expand Down
1 change: 1 addition & 0 deletions pkg/platform/resource_oidc_identity_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewOIDCIdentityMappingResource() resource.Resource {
func (r *odicIdentityMappingResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_oidc_identity_mapping"
}

func (r *odicIdentityMappingResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
Expand Down

0 comments on commit eee7ea9

Please sign in to comment.